{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime\n",
    "import logging\n",
    "\n",
    "from IPython.display import display, Markdown\n",
    "import snakemd\n",
    "\n",
    "from garmindb import GarminConnectConfigManager\n",
    "from garmindb.garmindb import GarminDb, Attributes, ActivitiesDb, Activities\n",
    "\n",
    "from graphs import Graph\n",
    "\n",
    "\n",
    "logging.basicConfig(filename='weekly.log', filemode='w', level=logging.INFO)\n",
    "logger = logging.getLogger(\"weekly\")\n",
    "\n",
    "\n",
    "def match_day(day, data):\n",
    "    for entry in data:\n",
    "        if entry.start_time.date() == day:\n",
    "            return entry.training_load\n",
    "    return 0.0\n",
    "\n",
    "def activities_to_sequence(days, data):\n",
    "    sequence = []\n",
    "    for day in days:\n",
    "        sequence.append(match_day(day, data))\n",
    "    return sequence\n",
    "\n",
    "\n",
    "gc_config = GarminConnectConfigManager()\n",
    "db_params_dict = gc_config.get_db_params()\n",
    "\n",
    "num_of_days = 30\n",
    "\n",
    "garmin_db = GarminDb(db_params_dict)\n",
    "garmin_act_db = ActivitiesDb(db_params_dict)\n",
    "measurement_system = Attributes.measurements_type(garmin_db)\n",
    "\n",
    "doc = snakemd.new_doc()\n",
    "\n",
    "end_ts = datetime.datetime.now()\n",
    "start_ts = datetime.datetime.now() - datetime.timedelta(days=7)\n",
    "\n",
    "doc.add_heading(f\"Update for {start_ts.date()} - {end_ts.date()}\")\n",
    "display(Markdown(str(doc)))\n",
    "\n",
    "graph = Graph()\n",
    "\n",
    "graph.graph_activity('rhr', 'days', num_of_days)\n",
    "\n",
    "\n",
    "graph.graph_activity('weight', 'days', num_of_days)\n",
    "\n",
    "days = [datetime.date.today() - datetime.timedelta(days=day) for day in range(num_of_days)]\n",
    "data = Activities.get_for_period(garmin_act_db, start_ts, end_ts)\n",
    "training_load = activities_to_sequence(days, data)\n",
    "graph._graph_scatter(days, training_load, 'Training Load', 'load')\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
